package uk.gov.swmprobation.swm;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.Html;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

public class Mission extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.activity_mission);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar);

		TextView mission = (TextView) findViewById(R.id.mission);
		mission.setText(Html.fromHtml(readText(R.raw.mission)));

	}

	private String readText(int rawfile) {
		InputStream inputStream = getResources().openRawResource(rawfile);
		ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

		int i;

		try {
			i = inputStream.read();
			while (i != -1) {
				byteArrayOutputStream.write(i);
				i = inputStream.read();
			}
			inputStream.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return byteArrayOutputStream.toString();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.activity_mission, menu);
		return true;
	}
	
	public void homeWebsite(View view) {
    	Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.swmprobation.gov.uk"));
    	startActivity(intent);
    }
	
}
